<template>
  <div v-loading="loading">
    <el-form ref="form" :model="form" :rules="rules" label-width="120px" class="dataForm">
      <el-row>
        <el-col :span="12">
          <el-form-item :label="$t('文件类型')" prop="fileType">
            <dict-select
              v-model="form.fileType"
              dictionary="disclosure_file_type"
              :placeholder="$t('文件类型')"
            />
          </el-form-item>
        </el-col>
        <el-col :span="12">
          <el-form-item :label="$t('报告期')" prop="reportStage">
            <el-input v-model="form.reportStage" :placeholder="$t('报告期')" show-word-limit maxlength="32" />
          </el-form-item>
        </el-col>
        <el-col :span="24">
          <el-form-item :label="$t('备注')" prop="remark">
            <el-input v-model="form.remark" type="textarea" maxlength="2000" show-word-limit :placeholder="$t('备注')" />
          </el-form-item>
        </el-col>
      </el-row>
      <FileTable :list.sync="form.fileList" data-type="bf_disclosure" :business-id="getDealId" :btn-show="!otherBtnHide" />
    </el-form>
    <div slot="footer" class="dialog-footer" style="text-align: right;">
      <!--保存 取消按钮-->
      <save-btn has-permi="bf:disclosure" />
    </div>
  </div>
</template>

<script>
    import { saveBfDisclosureInfo, getBfDisclosureInfo } from '@/api/bf/disclosure/bfDisclosureInfo'
    export default {
        data() {
            return {
                otherBtnHide: false,
                // 表单参数
                form: {
                  fileList: []
                },
                // 项目id
                getDealId: this.$route.query.id,
                // 遮罩层
                loading: false,
                // 表单校验
                rules: {
                  fileType: [{ required: true, message: this.$t('必填信息'), trigger: 'blur' }]
                }
            }
        },
        mounted() {
            if (this.getDealId === undefined || this.getDealId === '' || this.getDealId === null) {
                this.getDealId = this.$route.query.lpId
            }
        },
        created() {
            this.getDicts('disclosure_file_type').then(response => {
                this.fileTypeOptions = response.data
            })
        },
        methods: {
            // 初始化数据
            init(data) {
              this.loading = true
                if (data != null && data.id !== undefined) {
                    getBfDisclosureInfo(data.id).then(response => {
                        this.form = response.data
                        this.loading = false
                    })
                } else {
                    this.reset()
                    this.loading = false
                }
            },
            // 表单重置
            reset() {
                this.form = {
                    id: undefined,
                    dealId: this.getDealId ? this.getDealId : undefined,
                    fileType: undefined,
                    reportStage: undefined,
                    remark: undefined,
                    fileList: [],
                    createBy: undefined,
                    createTime: undefined,
                    updateBy: undefined,
                    updateTime: undefined,
                    delFlag: undefined
                }
                this.resetForm('form')
            },
            // 取消按钮
            cancel() {
                this.$parent.$parent.formOpen = false
                this.$parent.$parent.reset()
            },
            // 关闭form页面
            closeForm() {
                // 关闭form页面遮罩层
                this.loading = false
                // 关闭form页面
                this.$parent.$parent.formOpen = false
                if (this.$parent.$parent.getBfDisclosureList !== undefined) {
                  this.$parent.$parent.getBfDisclosureList()
                }
                // 刷新list页面
                if (this.$parent.$parent.getList !== undefined) {
                  this.$parent.$parent.getList()
                }
            },
            /** 提交按钮 */
            submitForm: function() {
                this.$refs['form'].validate(valid => {
                    if (valid) {
                        this.loading = true
                        saveBfDisclosureInfo(this.form).then(response => {
                            if (response.code === 200) {
                                this.msgSuccess(this.$t('保存成功'))
                                this.closeForm()
                            } else {
                                this.msgError(response.msg)
                            }
                            this.loading = false
                        })
                    } else {
                      this.locationError(document)
                    }
                })
           }

        }

    }
</script>
